﻿namespace DataServer.ApplicationLib.Rules
{
    public class VerifySuccessDecorator : ConfigDataRuleBase, IRuleDecorator
    {
        private IConfigDataRule? _configDataRule;

        public VerifySuccessDecorator(RuleContext ruleContext) : base(ruleContext)
        {
        }

        public void SetDataRule(IConfigDataRule configDataRule)
        {
            _configDataRule = configDataRule;
        }

        public override async Task<VerifyRuleResult> VerifyData()
        {
            var result = VerifyRuleResult.Default;

            if (_configDataRule != null)
            {
                result = await _configDataRule.VerifyData();
                if (result != null && result.IsValid)
                {
                    this.RunByRuleType(RuleType.AfterSuccess);
                }
            }

            return result;
        }

    }
}
